package com.xl.ssh.config;

import com.xl.ssh.handler.SSHWebSocketHandler;
import com.xl.ssh.intercepter.SSHWebSocketIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * 使用配置的方式，创建了一个原生的websocket的连接点
 */
@Configuration
public class SSHWebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SSHWebSocketHandler sshWebSocketHandler ;
    @Autowired
    private SSHWebSocketIntercepter sshWebSocketIntercepter;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(sshWebSocketHandler, "/sshSocket")
                .addInterceptors(sshWebSocketIntercepter)
                .setAllowedOrigins("*");
    }
}
